using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Management;
using System.Text;
using System.Windows.Forms;

namespace csharpsysinfo
{
    public partial class memoryUsageForm : Form
    {
        string formFactorString, memoryTypeString;
        decimal totalPageFileSizeDecimal, freePageFileSizeDecimal, usedPageFileSizeDecimal,
                totalVirtualMemSizeDecimal, freeVirtualMemSizeDecimal, usedVirtualMemSizeDecimal;



        public memoryUsageForm()
        {
            InitializeComponent();
        }

        private void okMuButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private string GetMemorySize()
        {
            string memSizeString;
            int genericCounterInteger;
            decimal totalMemSizeDecimal, inUseMemSizeDecimal, freeToDecCalcDecimal,
                    percentUsedRamDecimal;

            genericCounterInteger = 1;

            memSizeString = "Failed to retrieve info.";
            totalMemSizeDecimal = 0;

            try
            {
                ManagementObjectSearcher managementobjectsearcher = new ManagementObjectSearcher
                ("SELECT * FROM  Win32_PhysicalMemory");

                ManagementObjectCollection managementobjectcollection = managementobjectsearcher.Get();

                foreach (ManagementObject mob in managementobjectcollection)
                {
                    if (genericCounterInteger == 1)
                    {
                        memSizeString = mob.Properties["Capacity"].Value.ToString();
                        totalMemSizeDecimal = Decimal.Parse(memSizeString);
                        memAmountBank0TextBox.Text = memSizeString;
                    }

                    if (genericCounterInteger == 2)
                    {
                        memSizeString = mob.Properties["Capacity"].Value.ToString();
                        totalMemSizeDecimal = totalMemSizeDecimal + Decimal.Parse(memSizeString);
                        memAmountBank1TextBox.Text = memSizeString;
                    }
                    if (genericCounterInteger == 3)
                    {
                        memSizeString = mob.Properties["Capacity"].Value.ToString();
                        totalMemSizeDecimal = totalMemSizeDecimal + Decimal.Parse(memSizeString);
                        memAmountBank2TextBox.Text = memSizeString;
                    }
                    if (genericCounterInteger == 4)
                    {
                        memSizeString = mob.Properties["Capacity"].Value.ToString();
                        totalMemSizeDecimal = totalMemSizeDecimal + Decimal.Parse(memSizeString);
                        memAmountBank3TextBox.Text = memSizeString;
                    }
                    genericCounterInteger++;
                }
                sizeRamTextBox.Text = totalMemSizeDecimal.ToString();
            }
            catch
            {
            }
            GetFreeMemorySize();
            freeToDecCalcDecimal = Decimal.Parse(GetFreeMemorySize());
            inUseMemSizeDecimal = totalMemSizeDecimal - (freeToDecCalcDecimal * 1024);
            usedRamTextBox.Text = inUseMemSizeDecimal.ToString();

            percentUsedRamDecimal = (inUseMemSizeDecimal / totalMemSizeDecimal);
            percentCapacityPhysicalMemTextBox.Text = percentUsedRamDecimal.ToString("P");

            return memSizeString;

        }
    

        private string GetDeviceLocator()
        {
            string deviceLocatorString;
            int genericCounterInteger;

            genericCounterInteger = 1;

            deviceLocatorString = "Failed to retrieve info.";

            try
            {
                ManagementObjectSearcher managementobjectsearcher = new ManagementObjectSearcher
                ("SELECT * FROM  Win32_PhysicalMemory");

                ManagementObjectCollection managementobjectcollection = managementobjectsearcher.Get();

                foreach (ManagementObject mob in managementobjectcollection)
                {
                    if (genericCounterInteger == 1)
                    {
                        deviceLocatorString = mob.Properties["DeviceLocator"].Value.ToString();
                        deviceLocator0TextBox.Text = deviceLocatorString;
                    }

                    if (genericCounterInteger == 2)
                    {
                        deviceLocatorString = mob.Properties["DeviceLocator"].Value.ToString();
                        deviceLocator1TextBox.Text = deviceLocatorString;
                    }
                    if (genericCounterInteger == 3)
                    {
                        deviceLocatorString = mob.Properties["DeviceLocator"].Value.ToString();
                        deviceLocator2TextBox.Text = deviceLocatorString;
                    }
                    if (genericCounterInteger == 4)
                    {
                        deviceLocatorString = mob.Properties["DeviceLocator"].Value.ToString();
                        deviceLocator3TextBox.Text = deviceLocatorString;
                    }
                    genericCounterInteger++;
                }
            }
            catch
            {
            }
            return deviceLocatorString;

        }

        private string GetFormFactor()
        {
            //string formFactorString;
            int genericCounterInteger;

            genericCounterInteger = 1;

            formFactorString = "Failed to retrieve info.";

            try
            {
                ManagementObjectSearcher managementobjectsearcher = new ManagementObjectSearcher
                ("SELECT * FROM  Win32_PhysicalMemory");

                ManagementObjectCollection managementobjectcollection = managementobjectsearcher.Get();

                foreach (ManagementObject mob in managementobjectcollection)
                {
                    if (genericCounterInteger == 1)
                    {
                        formFactorString = mob.Properties["FormFactor"].Value.ToString();
                        FormFactorFormat();
                        formFactor0TextBox.Text = FormFactorFormat();
                    }

                    if (genericCounterInteger == 2)
                    {
                        formFactorString = mob.Properties["FormFactor"].Value.ToString();
                        FormFactorFormat();
                        formFactor1TextBox.Text = FormFactorFormat();
                    }
                    if (genericCounterInteger == 3)
                    {
                        formFactorString = mob.Properties["FormFactor"].Value.ToString();
                        FormFactorFormat();
                        formFactor2TextBox.Text = FormFactorFormat();
                    }
                    if (genericCounterInteger == 4)
                    {
                        formFactorString = mob.Properties["FormFactor"].Value.ToString();
                        FormFactorFormat();
                        formFactor3TextBox.Text = FormFactorFormat();
                    }
                    genericCounterInteger++;
                }
            }
            catch
            {
            }
            return formFactorString;

        }

        private string FormFactorFormat()
        {
            string formFactorFormatString, zeroString = "0", oneString = "1", twoString = "2",
                threeString = "3", fourString = "4", fiveString = "5", sixString = "6", 
                sevenString = "7", eightString = "8", nineString = "9", tenString = "10",
                elevenString = "11", twelveString = "12", thirteenString = "13",
                fourteenString = "14", fifteenString = "15", sixteenString = "16",
                seventeenString = "17", eighteenString = "18", nineteenString = "19",
                twentyString = "20", twentyOneString = "21", twentyTwoString = "22",
                twentyThreeString = "23";
            
            formFactorFormatString = "Failed to retrieve info.";



            if (formFactorString == zeroString)
            {
                formFactorFormatString = "Unknown";
            }

            if (formFactorString == oneString)
            {
                formFactorFormatString = "Other";
            }

            if (formFactorString == twoString)
            {
                formFactorFormatString = "SIP";
            }

            if (formFactorString == threeString)
            {
                formFactorFormatString = "DIP";
            }

            if (formFactorString == fourString)
            {
                formFactorFormatString = "ZIP";
            }

            if (formFactorString == fiveString)
            {
                formFactorFormatString = "SOJ";
            }

            if (formFactorString == sixString)
            {
                formFactorFormatString = "Proprietary";
            }

            if (formFactorString == sevenString)
            {
                formFactorFormatString = "SIMM";
            }

            if (formFactorString == eightString)
            {
                formFactorFormatString = "DIMM";
            }

            if (formFactorString == nineString)
            {
                formFactorFormatString = "TSOP";
            }

            if (formFactorString == tenString)
            {
                formFactorFormatString = "PGA";
            }

            if (formFactorString == elevenString)
            {
                formFactorFormatString = "RIMM";
            }

            if (formFactorString == twelveString)
            {
                formFactorFormatString = "SODIMM";
            }

            if (formFactorString == thirteenString)
            {
                formFactorFormatString = "SRIMM";
            }

            if (formFactorString == fourteenString)
            {
                formFactorFormatString = "SMD";
            }

            if (formFactorString == fifteenString)
            {
                formFactorFormatString = "SSMP";
            }

            if (formFactorString == sixteenString)
            {
                formFactorFormatString = "QFP";
            }

            if (formFactorString == seventeenString)
            {
                formFactorFormatString = "TQFP";
            }

            if (formFactorString == eighteenString)
            {
                formFactorFormatString = "SOIC";
            }

            if (formFactorString == nineteenString)
            {
                formFactorFormatString = "LCC";
            }

            if (formFactorString == twentyString)
            {
                formFactorFormatString = "PLCC";
            }

            if (formFactorString == twentyOneString)
            {
                formFactorFormatString = "BGA";
            }

            if (formFactorString == twentyTwoString)
            {
                formFactorFormatString = "FPBGA";
            }

            if (formFactorString == twentyThreeString)
            {
                formFactorFormatString = "LGA";
            }

            return formFactorFormatString;
        }

        private string GetMemSpeed()
        {
            string memSpeedString;
            int genericCounterInteger;

            genericCounterInteger = 1;

            memSpeedString = "Failed to retrieve info.";


                ManagementObjectSearcher managementobjectsearcher = new ManagementObjectSearcher
                ("SELECT * FROM  Win32_PhysicalMemory");

                ManagementObjectCollection managementobjectcollection = managementobjectsearcher.Get();

                foreach (ManagementObject mob in managementobjectcollection)
                {
                    try
                    {
                        if (genericCounterInteger == 1)
                        {
                            memSpeedString = mob.Properties["Speed"].Value.ToString();
                            speed0TextBox.Text = memSpeedString;
                        }
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (genericCounterInteger == 2)
                        {
                            memSpeedString = mob.Properties["Speed"].Value.ToString();
                            speed1TextBox.Text = memSpeedString;
                        }
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (genericCounterInteger == 3)
                        {
                            memSpeedString = mob.Properties["Speed"].Value.ToString();
                            speed2TextBox.Text = memSpeedString;
                        }
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (genericCounterInteger == 4)
                        {
                            memSpeedString = mob.Properties["Speed"].Value.ToString();
                            speed3TextBox.Text = memSpeedString;
                        }
                    }
                    catch
                    {
                    }

                    genericCounterInteger++;
                }

            return memSpeedString;

        }

        private string GetMemoryType()
        {
            
            int genericCounterInteger;

            genericCounterInteger = 1;

            memoryTypeString = "Failed to retrieve info.";

            try
            {
                ManagementObjectSearcher managementobjectsearcher = new ManagementObjectSearcher
                ("SELECT * FROM  Win32_PhysicalMemory");

                ManagementObjectCollection managementobjectcollection = managementobjectsearcher.Get();

                foreach (ManagementObject mob in managementobjectcollection)
                {
                    if (genericCounterInteger == 1)
                    {
                        memoryTypeString = mob.Properties["MemoryType"].Value.ToString();
                        MemoryTypeFormat();
                        memoryType0TextBox.Text = MemoryTypeFormat();
                    }

                    if (genericCounterInteger == 2)
                    {
                        memoryTypeString = mob.Properties["MemoryType"].Value.ToString();
                        MemoryTypeFormat();
                        memoryType1TextBox.Text = MemoryTypeFormat();
                    }
                    if (genericCounterInteger == 3)
                    {
                        memoryTypeString = mob.Properties["MemoryType"].Value.ToString();
                        MemoryTypeFormat();
                        memoryType2TextBox.Text = MemoryTypeFormat();
                    }
                    if (genericCounterInteger == 4)
                    {
                        memoryTypeString = mob.Properties["MemoryType"].Value.ToString();
                        MemoryTypeFormat();
                        memoryType3TextBox.Text = MemoryTypeFormat();
                    }
                    genericCounterInteger++;
                }
            }
            catch
            {
            }
            return memoryTypeString;

        }

        private string MemoryTypeFormat()
        {
            string memoryTypeFormatString, zeroString = "0", oneString = "1", twoString = "2",
            threeString = "3", fourString = "4", fiveString = "5", sixString = "6",
            sevenString = "7", eightString = "8", nineString = "9", tenString = "10",
            elevenString = "11", twelveString = "12", thirteenString = "13",
            fourteenString = "14", fifteenString = "15", sixteenString = "16",
            seventeenString = "17", eighteenString = "18", nineteenString = "19",
            twentyString = "20", twentyOneString = "21";

            memoryTypeFormatString = "Failed to retrieve info.";



            if (memoryTypeString == zeroString)
            {
                memoryTypeFormatString = "Unknown";
            }

            if (memoryTypeString == oneString)
            {
                memoryTypeFormatString = "Other";
            }

            if (memoryTypeString == twoString)
            {
                memoryTypeFormatString = "DRAM";
            }

            if (memoryTypeString == threeString)
            {
                memoryTypeFormatString = "Synchronous DRAM";
            }

            if (memoryTypeString == fourString)
            {
                memoryTypeFormatString = "Cache DRAM";
            }

            if (memoryTypeString == fiveString)
            {
                memoryTypeFormatString = "EDO";
            }

            if (memoryTypeString == sixString)
            {
                memoryTypeFormatString = "EDRAM";
            }

            if (memoryTypeString == sevenString)
            {
                memoryTypeFormatString = "VRAM";
            }

            if (memoryTypeString == eightString)
            {
                memoryTypeFormatString = "SRAM";
            }

            if (memoryTypeString == nineString)
            {
                memoryTypeFormatString = "RAM";
            }

            if (memoryTypeString == tenString)
            {
                memoryTypeFormatString = "ROM";
            }

            if (memoryTypeString == elevenString)
            {
                memoryTypeFormatString = "Flash";
            }

            if (memoryTypeString == twelveString)
            {
                memoryTypeFormatString = "EEPROM";
            }

            if (memoryTypeString == thirteenString)
            {
                memoryTypeFormatString = "FEPROM";
            }

            if (memoryTypeString == fourteenString)
            {
                memoryTypeFormatString = "EPROM";
            }

            if (memoryTypeString == fifteenString)
            {
                memoryTypeFormatString = "CDRAM";
            }

            if (memoryTypeString == sixteenString)
            {
                memoryTypeFormatString = "3DRAM";
            }

            if (memoryTypeString == seventeenString)
            {
                memoryTypeFormatString = "SDRAM";
            }

            if (memoryTypeString == eighteenString)
            {
                memoryTypeFormatString = "SGRAM";
            }

            if (memoryTypeString == nineteenString)
            {
                memoryTypeFormatString = "RDRAM";
            }

            if (memoryTypeString == twentyString)
            {
                memoryTypeFormatString = "DDR";
            }

            if (memoryTypeString == twentyOneString)
            {
                memoryTypeFormatString = "DDR-2";
            }

            return memoryTypeFormatString;
        }


        private string GetFreeMemorySize()
        {
            string memSizeFreeString;
            decimal memSizeFreeDecimal;

            memSizeFreeString = "Failed to retrieve info.";


            try
            {
                ManagementObjectSearcher managementobjectsearcher = new ManagementObjectSearcher
                ("SELECT * FROM  Win32_OperatingSystem");

                ManagementObjectCollection managementobjectcollection = managementobjectsearcher.Get();

                foreach (ManagementObject mob in managementobjectcollection)
                {
                    memSizeFreeString = mob.Properties["FreePhysicalMemory"].Value.ToString();
                    memSizeFreeDecimal = decimal.Parse(memSizeFreeString) * 1024;   
                    freeRamTextBox.Text = memSizeFreeDecimal.ToString();
                }
            }
            catch
            {
            }
            return memSizeFreeString;

        }


        private string GetVirtualMemorySize()
        {
            string totalVirtualMemoryString;
            decimal totalVirtualMemoryDecimal;
            totalVirtualMemoryString = "Failed to retrieve info.";


            try
            {
                ManagementObjectSearcher managementobjectsearcher = new ManagementObjectSearcher
                ("SELECT * FROM  Win32_OperatingSystem");

                ManagementObjectCollection managementobjectcollection = managementobjectsearcher.Get();

                foreach (ManagementObject mob in managementobjectcollection)
                {
                    totalVirtualMemoryString = mob.Properties["TotalVirtualMemorySize"].Value.ToString();
                    totalVirtualMemoryDecimal = Decimal.Parse(totalVirtualMemoryString) * 1024;
                    virtualMemTotalTextBox.Text = totalVirtualMemoryDecimal.ToString();
                }
            }
            catch
            {
            }
            return totalVirtualMemoryString;

        }


        private string GetFreeVirtualMemorySize()
        {
            //this is reporting incorrect results
            string freeVirtualMemoryString;
            decimal freeVirtualMemoryDecimal;
            freeVirtualMemoryString = "Failed to retrieve info.";


            try
            {
                ManagementObjectSearcher managementobjectsearcher = new ManagementObjectSearcher
                ("SELECT * FROM  Win32_OperatingSystem");

                ManagementObjectCollection managementobjectcollection = managementobjectsearcher.Get();

                foreach (ManagementObject mob in managementobjectcollection)
                {
                    freeVirtualMemoryString = mob.Properties["FreeVirtualMemory"].Value.ToString();
                    freeVirtualMemoryDecimal = Decimal.Parse(freeVirtualMemoryString) *1024;
                    virtualMemFreeTextBox.Text = freeVirtualMemoryDecimal.ToString();
                }
            }
            catch
            {
            }
            return freeVirtualMemoryString;

        }


        private string GetPageFileSize()
        {
            string totalPageFileString;
            decimal totalPageFileDecimal;
            totalPageFileString = "Failed to retrieve info.";


            try
            {
                ManagementObjectSearcher managementobjectsearcher = new ManagementObjectSearcher
                ("SELECT * FROM  Win32_OperatingSystem");

                ManagementObjectCollection managementobjectcollection = managementobjectsearcher.Get();

                foreach (ManagementObject mob in managementobjectcollection)
                {
                    totalPageFileString = mob.Properties["SizeStoredInPagingFiles"].Value.ToString();
                    totalPageFileDecimal = Decimal.Parse(totalPageFileString) * 1024;
                    pageFileTotalTextBox.Text = totalPageFileDecimal.ToString();
                }
            }
            catch
            {
            }
            return totalPageFileString;

        }


        private string GetFreePageFileSize()
        {
            string freePageFileString;
            decimal freePageFileDecimal;
            freePageFileString = "Failed to retrieve info.";


            try
            {
                ManagementObjectSearcher managementobjectsearcher = new ManagementObjectSearcher
                ("SELECT * FROM  Win32_OperatingSystem");

                ManagementObjectCollection managementobjectcollection = managementobjectsearcher.Get();

                foreach (ManagementObject mob in managementobjectcollection)
                {
                    freePageFileString = mob.Properties["FreeSpaceInPagingFiles"].Value.ToString();
                    freePageFileDecimal = Decimal.Parse(freePageFileString) * 1024;
                    pageFileFreeTextBox.Text = freePageFileDecimal.ToString();
                }
            }
            catch
            {
            }
            return freePageFileString;

        }
        private void FillMissingInfoWithNa()
        {
            if (memAmountBank3TextBox.Text == "")
            {
                memAmountBank3TextBox.Text = "N/A";
            }
            if (memAmountBank2TextBox.Text == "")
            {
                memAmountBank2TextBox.Text = "N/A";
            }
            if (memAmountBank1TextBox.Text == "")
            {
                memAmountBank1TextBox.Text = "N/A";
            }
            if (memAmountBank0TextBox.Text == "")
            {
                memAmountBank0TextBox.Text = "N/A";
            }
            if (deviceLocator3TextBox.Text == "")
            {
                deviceLocator3TextBox.Text = "N/A";
            }
            if (deviceLocator2TextBox.Text == "")
            {
                deviceLocator2TextBox.Text = "N/A";
            }
            if (deviceLocator1TextBox.Text == "")
            {
                deviceLocator1TextBox.Text = "N/A";
            }
            if (deviceLocator0TextBox.Text == "")
            {
                deviceLocator0TextBox.Text = "N/A";
            }
            if (formFactor3TextBox.Text == "")
            {
                formFactor3TextBox.Text = "N/A";
            }
            if (formFactor2TextBox.Text == "")
            {
                formFactor2TextBox.Text = "N/A";
            }
            if (formFactor1TextBox.Text == "")
            {
                formFactor1TextBox.Text = "N/A";
            }
            if (formFactor0TextBox.Text == "")
            {
                formFactor0TextBox.Text = "N/A";
            }
            if (speed3TextBox.Text == "")
            {
                speed3TextBox.Text = "N/A";
            }
            if (speed2TextBox.Text == "")
            {
                speed2TextBox.Text = "N/A";
            }
            if (speed1TextBox.Text == "")
            {
                speed1TextBox.Text = "N/A";
            }
            if (speed0TextBox.Text == "")
            {
                speed0TextBox.Text = "N/A";
            }
            if (memoryType3TextBox.Text == "")
            {
                memoryType3TextBox.Text = "N/A";
            }
            if (memoryType2TextBox.Text == "")
            {
                memoryType2TextBox.Text = "N/A";
            }
            if (memoryType1TextBox.Text == "")
            {
                memoryType1TextBox.Text = "N/A";
            }
            if (memoryType0TextBox.Text == "")
            {
                memoryType0TextBox.Text = "N/A";
            }
            
        }
        private void memoryUsageForm_Load(object sender, EventArgs e)
        {
            decimal percentUsedPageFileDecimal, percentUsedVirtualRamDecimal;

            GetMemorySize();
            GetDeviceLocator();
            GetFormFactor();
            GetMemSpeed();
            GetMemoryType();
            GetVirtualMemorySize();
            GetFreeVirtualMemorySize();
            GetPageFileSize();
            GetFreePageFileSize();
            FillMissingInfoWithNa();

            freePageFileSizeDecimal = Decimal.Parse(GetFreePageFileSize());
            totalPageFileSizeDecimal = Decimal.Parse(GetPageFileSize());
            usedPageFileSizeDecimal = (totalPageFileSizeDecimal * 1024) - (freePageFileSizeDecimal * 1024);
            pageFileUsedTextBox.Text = usedPageFileSizeDecimal.ToString();

            percentUsedPageFileDecimal = (usedPageFileSizeDecimal / (totalPageFileSizeDecimal * 1024));
            percentCapacityPageFileTextBox.Text = percentUsedPageFileDecimal.ToString("P");


            totalVirtualMemSizeDecimal = Decimal.Parse(GetVirtualMemorySize());
            freeVirtualMemSizeDecimal = Decimal.Parse(GetFreeVirtualMemorySize());
            usedVirtualMemSizeDecimal = (totalVirtualMemSizeDecimal * 1024) - (freeVirtualMemSizeDecimal * 1024);
            virtualMemUsedTextBox.Text = usedVirtualMemSizeDecimal.ToString();

            percentUsedVirtualRamDecimal = (usedVirtualMemSizeDecimal / (totalVirtualMemSizeDecimal * 1024));
            percentCapacityVirtualMemTextBox.Text = percentUsedVirtualRamDecimal.ToString("P");


        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void convertToMegToolStripMenuItem_Click(object sender, EventArgs e)
        {
            decimal convertFreeRamDecimal, freeRamDecimal, convertUsedRamDecimal, usedRamDecimal,
                convertTotalRamDecimal, totalRamDecimal, convertTotalVirtualMemDecimal,
                totalVirtualMemDecimal, freeVirtualMemDecimal, convertFreeVirtualMemDecimal,
                usedVirtualMemDecimal, convertUsedVirtualMemDecimal, usedPageFileMemDecimal,
                convertUsedPageFileMemDecimal, totalPageFileDecimal, convertTotalPageFileDecimal,
                freePageFileDecimal, convertFreePageFileDecimal;

            freeRamDecimal = decimal.Parse(freeRamTextBox.Text);
            convertFreeRamDecimal = ((freeRamDecimal / 1024) / 1024);
            freeRamTextBox.Text = convertFreeRamDecimal.ToString();

            usedRamDecimal = decimal.Parse(usedRamTextBox.Text);
            convertUsedRamDecimal = ((usedRamDecimal / 1024) / 1024);
            usedRamTextBox.Text = convertUsedRamDecimal.ToString();

            totalRamDecimal = decimal.Parse(sizeRamTextBox.Text);
            convertTotalRamDecimal = ((totalRamDecimal / 1024) / 1024);
            sizeRamTextBox.Text = convertTotalRamDecimal.ToString();

            totalVirtualMemDecimal = decimal.Parse(virtualMemTotalTextBox.Text);
            convertTotalVirtualMemDecimal = ((totalVirtualMemDecimal / 1024) / 1024);
            virtualMemTotalTextBox.Text = convertTotalVirtualMemDecimal.ToString();

            freeVirtualMemDecimal = decimal.Parse(virtualMemFreeTextBox.Text);
            convertFreeVirtualMemDecimal = ((freeVirtualMemDecimal / 1024) / 1024);
            virtualMemFreeTextBox.Text = convertFreeVirtualMemDecimal.ToString();

            usedVirtualMemDecimal = decimal.Parse(virtualMemUsedTextBox.Text);
            convertUsedVirtualMemDecimal = ((usedVirtualMemDecimal / 1024) / 1024);
            virtualMemUsedTextBox.Text = convertUsedVirtualMemDecimal.ToString();

            usedPageFileMemDecimal = decimal.Parse(pageFileUsedTextBox.Text);
            convertUsedPageFileMemDecimal = ((usedPageFileMemDecimal / 1024) / 1024);
            pageFileUsedTextBox.Text = convertUsedPageFileMemDecimal.ToString();

            totalPageFileDecimal = decimal.Parse(pageFileTotalTextBox.Text);
            convertTotalPageFileDecimal = ((totalPageFileDecimal / 1024) / 1024);
            pageFileTotalTextBox.Text = convertTotalPageFileDecimal.ToString();

            freePageFileDecimal = decimal.Parse(pageFileFreeTextBox.Text);
            convertFreePageFileDecimal = ((freePageFileDecimal / 1024) / 1024);
            pageFileFreeTextBox.Text = convertFreePageFileDecimal.ToString();

            convertToMegToolStripMenuItem.Enabled = false;
            convertToMegButton.Enabled = false;
        }

        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            decimal percentUsedVirtualRamDecimal, percentUsedPageFileDecimal; 

            GetMemorySize();
            //GetDeviceLocator();
            //GetFormFactor();
            //GetMemSpeed();
            //GetMemoryType();
            GetVirtualMemorySize();
            GetFreeVirtualMemorySize();
            GetPageFileSize();
            GetFreePageFileSize();

            totalPageFileSizeDecimal = Decimal.Parse(GetPageFileSize());
            freePageFileSizeDecimal = Decimal.Parse(GetFreePageFileSize());
            usedPageFileSizeDecimal = (totalPageFileSizeDecimal * 1024) - (freePageFileSizeDecimal * 1024);
            pageFileUsedTextBox.Text = usedPageFileSizeDecimal.ToString();

            percentUsedPageFileDecimal = (usedPageFileSizeDecimal / (totalPageFileSizeDecimal * 1024));
            percentCapacityPageFileTextBox.Text = percentUsedPageFileDecimal.ToString("P");

            totalVirtualMemSizeDecimal = Decimal.Parse(GetVirtualMemorySize());
            freeVirtualMemSizeDecimal = Decimal.Parse(GetFreeVirtualMemorySize());
            usedVirtualMemSizeDecimal = (totalVirtualMemSizeDecimal * 1024) - (freeVirtualMemSizeDecimal * 1024);
            virtualMemUsedTextBox.Text = usedVirtualMemSizeDecimal.ToString();

            percentUsedVirtualRamDecimal = (usedVirtualMemSizeDecimal / (totalVirtualMemSizeDecimal * 1024));
            percentCapacityVirtualMemTextBox.Text = percentUsedVirtualRamDecimal.ToString("P");

            convertToMegToolStripMenuItem.Enabled = true;
            convertToMegButton.Enabled = true;
        }

        private void refreshButton_Click(object sender, EventArgs e)
        {
            refreshToolStripMenuItem_Click(sender, e);
        }

        private void convertToMegButton_Click(object sender, EventArgs e)
        {
            convertToMegToolStripMenuItem_Click(sender, e);
        }



        /*TODO - add a menu that lets user decide how to view results
        3524591616 bytes (informal notation: kilobyte = 1024 bytes)
        bits 	28196732928
        bytes 	3524591616
        kilobits 	27535872
        kilobytes 	3441984
        megabits 	26890.5
        megabytes 	3361.3125
        gigabits 	26.26025390625
        gigabytes 	3.28253173828125
        terabytes 	0.00320559740066528
        petabytes 	3.13046621158719e-06*/





    }


}